package client.gui;

import java.awt.Graphics2D;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import client.gui.ingame.Screen;

public abstract class DisplayAble {
	private Screen parent = Screen.getInstance();

	public abstract Graphics2D draw(Graphics2D g);

	private KeyListener KeyAdapter = new KeyAdapter() {
		public void keyPressed(KeyEvent e) {
			switch (e.getKeyCode()) {
			case KeyEvent.VK_ESCAPE:
				exit();
			}
		}
	};

	{
		parent.setDisplay(this);
		parent.win.addKeyListener(KeyAdapter);
	}

	public void exit() {
		parent.win.removeKeyListener(getKeyAdapter());
		parent.setDisplay(null);
		parent.exit();
	}

	public void setKeyAdapter(KeyListener keyPressed) {
		parent.win.removeKeyListener(KeyAdapter);
		KeyAdapter = keyPressed;
		parent.win.addKeyListener(KeyAdapter);

	}

	public KeyListener getKeyAdapter() {
		return KeyAdapter;
	}

}
